package com.TIEmulator.JNI;

import java.nio.ByteBuffer;

public final class NLib
{
  private static boolean is_shutdown = 0;
  private static final String lib = "TIEmulator";
  private static Object listener = null;

  public static boolean LoadLib()
  {
    int i;
    try
    {
      System.loadLibrary("TIEmulator");
      i = 1;
      return i;
    }
    catch (UnsatisfiedLinkError localUnsatisfiedLinkError)
    {
      i = 0;
    }
  }

  private static void OnFatalError(String paramString)
  {
    if (listener instanceof BaseInterface)
      ((BaseInterface)listener).OnFatalError(paramString);
    while (true)
    {
      return;
      ThrowInterfaceNotBoundException("NativeEvents");
    }
  }

  private static void OnImageUpdate()
  {
    if (listener instanceof NativeEvents)
      ((NativeEvents)listener).OnImageUpdate();
    while (true)
    {
      return;
      ThrowInterfaceNotBoundException("NativeEvents");
    }
  }

  private static void OnTIEmuPostMsg(String paramString)
  {
    if (listener instanceof BaseInterface)
      ((BaseInterface)listener).OnPostMessage(paramString);
    while (true)
    {
      return;
      ThrowInterfaceNotBoundException("NativeEvents");
    }
  }

  private static void OnTIEmuStopped()
  {
    if (listener instanceof NativeEvents)
      ((NativeEvents)listener).OnTIEmuStopped();
    while (true)
    {
      return;
      ThrowInterfaceNotBoundException("NativeEvents");
    }
  }

  private static void ThrowInterfaceNotBoundException(String paramString)
  {
    if (is_shutdown)
      return;
    throw new NLibInterfaceNotBoundException(paramString);
  }

  public static native int getHeight();

  public static native int getWidth();

  public static native boolean postIntermediateKeyCode(int paramInt1, int paramInt2);

  public static native boolean postTIKeyCodeIdx(int paramInt);

  public static native String querryRomType();

  public static void setListener(Object paramObject)
  {
    if ((paramObject instanceof BaseInterface) || (paramObject instanceof NativeTestFilesEvents) || (paramObject instanceof NativeEvents))
    {
      listener = paramObject;
      return;
    }
    listener = null;
    throw new CannotBindNLibInterfaceException(paramObject);
  }

  public static native boolean startEmulation(ByteBuffer paramByteBuffer);

  public static void stop()
  {
    is_shutdown = true;
    listener = null;
    stopEmulation();
  }

  private static native void stopEmulation();

  public static native int[] transcodeCode(int[] paramArrayOfInt, int paramInt);

  public static native int[] transcodeCodeIdx(int[] paramArrayOfInt, int paramInt);
}
